package cn.yourkingda.module;
import java.util.List;

import org.nutz.ioc.annotation.InjectName;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import cn.yourkingda.pojo.Customer;
import cn.yourkingda.service.CustomerService;
import cn.yourkingda.util.MyJson;
@InjectName("customerModule")
@Fail("json")
public class CustomerModule {
	private CustomerService customerService;
	
	//展示客户
	@At("/mvc/customer/list")
	@Ok("json")
	@Fail("json")
	public List list(){
		return customerService.listCustomer();
	}
	//更新客户
	@At("/mvc/customer/update")
	@Ok("json")
	@Fail("json")
	public MyJson update(@Param("id") int id,@Param("..") Customer customer){
		customer.setId(id);
		return customerService.updateCustomer(customer);
	}
	//删除客户
	@At("/mvc/customer/del")
	@Ok("json")
	@Fail("json")
	public MyJson delete(@Param("id") int id){
		int status = customerService.delCustomer(id);
		MyJson myJson = new MyJson();
		String msg="";
		switch(status){
		case 1:msg="删除成功!";break;
		default:break;
		}
		myJson.setStatus(status);
		myJson.setMsg(msg);
		return myJson;
	}
	
}
